<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="author" content="王佳佳">
    <title>只是轮播的轮播图</title>
    <style>
        *
        {
            box-sizing: border-box;
        }
        body
        {
            margin: 0;
        }
        main
        {
            position: relative;
            width: 490px;
            height: 300px;
            margin: 50px auto;
            overflow: hidden;
        }
        main img
        {
            width: 100%;
            height: 100%;
            display: none;
        }
        main img.current
        {
            display: block;
        }

        section
        {
            position: absolute;
            /* border: 1px solid black; */
            width: 100px;
            height: 20px;
            line-height: 20px;
            display: flex;
            justify-content: space-between;
            margin-left: 195px;
            margin-top: -30px;
        }
        main div
        {
            border-radius: 50%;
            width: 20px;
            height: 20px;
            line-height: 20px;
            text-align: center;
            background-color: white;
            cursor: pointer;
        }
        main div.button
        {
            background-color: skyblue;
        }
        section.prev,section.next
        {
            position: absolute;
            width: 20px;
            height: 30px;
            line-height: 30px;
            padding-left: 3px;
            color: white;
            background-color: rgba(0, 0, 0, 0.5);
            cursor: pointer;
        }
        .prev
        {
            margin-left: -20px;
            margin-top: -155px;
        }
        .next
        {
            margin-left: 490px;
            margin-top: -155px;
        }
    </style>
</head>
<body>
    <script src="./jquery.js"></script>
    <main>
        <img class="current" src="./img/01.jpg" alt="">
        <img src="./img/02.jpg" alt="">
        <img src="./img/03.jpg" alt="">
        <img src="./img/04.jpg" alt="">
        <img src="./img/05.jpg" alt="">
        <section>
            <div class="button">1</div>
            <div>2</div>
            <div>3</div>
            <div>4</div>
            <div>5</div>
        </section>
        <section class="prev">&lt;</section>
        <section class="next">&gt;</section>
    </main>

</body>
</html>

<script>
    var timer = setInterval(nextimg,1000);
    var index = 0;
    //上一张
    function previmg()
    {
        index =  index == 0 ? $('img').length-1 : index -1;
        showimg();
        // console.log(index);
    }
    //下一张
    function nextimg()
    {
        // console.log(index);
        index = index == $('img').length-1 ? 0 : index +1;
        showimg();
        // console.log(index);
    }
    //展示图片
    function showimg()
    {
        $('img').eq(index).addClass('current').siblings().removeClass('current');
        $('div').eq(index).addClass('button').siblings().removeClass('button');
    }
    //按照指示灯展示图片
    $('div').mouseover(function()
    {
        index = $(this).index();
        showimg();
    });
    //鼠标进入main轮播停止
    $('main').hover(function()
        {
            clearInterval(timer);
            $('.prev').stop().animate({marginLeft:0},500);
            $('.next').stop().animate({marginLeft:470},500);
        },
        function()
        {
            if(timer)
            {
                timer = null;
            }
            timer = setInterval(nextimg,1000);
            $('.prev').stop().animate({marginLeft:-20},500);
            $('.next').stop().animate({marginLeft:490},500);
        }
    )
    //点击上一张
    $('.prev').click(function()
    {
        previmg();
    })
    //点击下一张
    $('.next').click(function()
    {
        nextimg();
    })
</script>
</script>